<template>
	<view class="container">
		<!-- 顶部导航 - 添加fixed类 -->
		<view class="header fixed">
			<view class="logo">
				 <u-image src="/static/logo.png" width="277rpx" height="80rpx" mode="aspectFit"></u-image>
             <view class="nav">
				<view 
					v-for="(item, index) in navItems" 
					:key="index"
					class="nav-item"
					:class="{ active: currentNav === index }"
					@click="handleNavClick(index, item)"
				>
					{{ item }}
				</view>
			</view>
		</view>
		</view>
		
		<!-- 占位元素，防止内容被fixed导航遮挡 -->
		<view class="header-placeholder"></view>
		<view class="content">
		<!-- 品牌大牌背书模块 -->
		<view class="brand-section">
			<view class="section-title">品牌【大牌背书】</view>
			<view class="brand-desc">各大品牌免费升级 提供授权</view>
			
			<swiper
				class="brand-swiper"
				:indicator-dots="false"
				:autoplay="true"
				:interval="3000"
				:duration="500"
				:display-multiple-items="4"
				circular
			>
				<swiper-item 
					v-for="(item, index) in brandList"
					:key="index"
					class="brand-item"
				>
					<u-image 
						:src="item.logo" 
						width="150rpx" 
						height="210rpx"
						mode="aspectFit"
					></u-image>
				</swiper-item>
			</swiper>
		</view>

		<!-- 上新有扶持模块 -->
		<view class="support-section">
			<view class="section-title">上新【有扶持】</view>
			<view class="section-desc">每周三上新品 联系客服领取数据包</view>
			
			<view class="support-content" :style="{ backgroundImage: `url(${supportBg})` }">
				<!-- 产品列表 -->
				<view class="product-grid">
					<view class="product-list">
						<view 
							v-for="(item, index) in supportProducts.slice(0, 3)" 
						:key="index"
						class="product-card"
					>
						<view class="product-info">
							<view class="tag">{{item.tag}}</view>
							<view class="title">{{item.title}}</view>
						</view>
						<u-image 
							:src="item.image" 
							width="170rpx" 
							height="70rpx"
							mode="aspectFill"
						></u-image>
						
					</view>
				</view>
					
					
					<!-- 查看更多 -->
					<view class="more-card" @click="handleViewMore">
						<u-icon name="arrow-right" size="20" color="#fff"></u-icon>
						<text>查看更多商品</text>
					</view>
				</view>
			</view>
		</view>

		<!-- 产品库模块 -->
		<view class="product-section" >
			<view class="section-title" @click="login">产品库【量大价优】</view>
			<view class="section-desc">免费提供授权 闪电发货 日发万单</view>
			
			<view class="product-list">
				<view class="product-item" v-for="(item, index) in productList" :key="index">
					
					<u-image 
						:src="item.image" 
						width="190rpx" 
						height="190rpx" class="product-image"
						mode="aspectFill"
					></u-image>
					<view class="product-info">
						<view class="product-name">{{item.name}}</view>
						<view class="product-price">{{item.price}}</view>
					</view>
					
				</view>
			</view>
		</view>
		</view>
	</view>
</template>

<script>
import {
		 postToken
	} from "@/api/index.js";

export default {
	data() {
		return {
			username: "",
			password: "",
			phone: "", // 手机号
			regpassword: "", // 注册密码
			tenantId: "000000",
			grant_type: "password",
			title:'标题',
			list: [
				{
					name:'选项一',
					subname:"选项一描述",
					color:'#ffaa7f',
					fontSize:'20'
				},
				{
					name: '选项二禁用',
					disabled:true
				},
				{
					name: '开启load加载', //开启后文字不显示
					loading:true
				}
			],
			show: false,
			
			// 新增导航数据
			navItems: ['爆品', '药贴', '乳膏', '水剂'],
			currentNav: 1,
			// 添加页面路径映射
			navRoutes: {
				'爆品': '/pages/index/index',
				'药贴': '/pages/yaotie/index',
				'乳膏': '/pages/rugao/index',
				'水剂': '/pages/shuiji/index',
				// '首页': '/pages/index/index'
			},
			// 品牌列表数据
			brandList: [
				{ logo: '/static/temp01.jpg' },
				{ logo: '/static/temp01.jpg' },
				{ logo: '/static/temp01.jpg' },
				{ logo: '/static/temp01.jpg' },
				{ logo: '/static/temp01.jpg' },
				{ logo: '/static/temp01.jpg' },
				{ logo: '/static/temp01.jpg' },
				{ logo: '/static/temp01.jpg' },
			],
			productList: [
				{
					image: '/static/temp01.jpg',
					name: '手足愈美霜',
					price: '3.2'
				},
				{
					image: '/static/product1.jpg',
					name: '手足愈美霜',
					price: '3.2'
				},
				{
					image: '/static/product1.jpg',
					name: '手足愈美霜',
					price: '3.2'
				},
				// ... 更多产品数据
			],
			supportBg: '/static/bg01.png', // 背景图片
			supportProducts: [
				{
					image: '/static/temp01.jpg',
					tag: '抖快爆款',
					title: '蒸汽暖膜贴'
				},
				{
					image: '/static/temp01.jpg',
					tag: '新品上架',
					title: '医用冷敷贴'
				},
				{
					image: '/static/temp01.jpg',
					tag: '热销产品',
					title: '关节贴'
				}
			]
		};
	},
	methods: {
		// 登录
		login() {
			console.log('1');
			let obj ={
				'aaa':1
			}
			// postToken(obj).then(res => {
			// 	console.log(res)
			// })

			console.log('点击登录按钮');
			// 使用uni.$u.http直接发起请求测试
			uni.$u.http.post('/blade-auth/oauth/token', obj).then(res => {
				console.log('登录成功', res)
			}).catch(err => {
				console.log('登录失败', err)
			})
		},
		handleNavClick(index, item) {
			this.currentNav = index;
			// 获取对应路由
			const route = this.navRoutes[item];
			if (route) {
				uni.navigateTo({
					url: route,
					fail: (err) => {
						// 如果页面已经在栈中，使用switchTab
							uni.switchTab({
								url: route
							});
					}
				});
			}
		},
		handleViewMore() {
			// 跳转到更多商品页面
			uni.navigateTo({
				url: '/pages/products/more'
			})
		}
	}
};
</script>

<style lang="scss" scoped>
.container {
	width: 100%;
}

.header {
	padding: 20rpx 30rpx;
	background-color: #fff;
	width: 100%;
	box-sizing: border-box;
	
	
	&.fixed {
		position: fixed;
		top: 0;
		left: 0;
		z-index: 999;
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
	}
	
	.logo {
		display: flex;
		margin-bottom: 20rpx;
	flex-direction: column;
		
		text {
			margin-left: 10rpx;
			font-size: 32rpx;
			font-weight: bold;
		}
	}
	
	.nav {
		display: flex; margin-top: 20rpx;;
		justify-content: space-around;
		
		.nav-item {
			padding: 10rpx 20rpx;
			font-size: 28rpx;
			
			&.active {
				color: #5677fc;font-weight: bold;
			}
		}
	}
}

// 添加占位元素样式
.header-placeholder {
	height: 190rpx; // 根据header实际高度调整
	width: 100%;
}

.content {
	padding: 30rpx;
	background: #eee;
}

.brand-section {
	padding: 10rpx;
	// background: #fff;
	margin-top: 20rpx;
	
	.section-title {
		font-size: 32rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}
	
	.brand-desc {
		font-size: 24rpx;
		color: #666;
		margin-bottom: 20rpx;
	}
	
	.brand-swiper {
		height: 210rpx;
		
		.brand-item {
			display: flex;
			width: 170rpx!important;
			margin-right: 80rpx;
			border-radius: 10rpx;
			// background: #fff;
			align-items: center;
			justify-content: center;
		}
	}
}

.support-section {
	padding: 10rpx;
	margin-top: 20rpx;
	
	.section-title {
		font-size: 32rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}
	
	.section-desc {
		font-size: 24rpx;
		color: #666;
		margin-bottom: 20rpx;
	}
	
	.support-content {
		height: 700rpx;
		background-size: cover;
		background-position: center;
		border-radius: 10rpx;
		 padding: 0 20rpx;
		position: relative;
		
		.product-grid {
			position: absolute;
			left: 20rpx;
			right: 20rpx;
			display: flex;
			bottom: 30rpx;
			flex-direction: column;
			height: 280rpx;
		}

		.product-list{
			display: flex;
			flex-direction: row;
			flex-wrap: nowrap;
			justify-content: space-between;
		}

		.u-image{
			margin-top: 150rpx;
		}

		
		
		.product-card {
			position: relative;
			width: 190rpx;
			height: 220rpx;
			border-radius: 20rpx;
			overflow: hidden;
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: row;
			background: #fff;
			
			/deep/ .u-image{
				margin-top: 70rpx;
				width: 180rpx;
				height: 90rpx;
			}
			
			.product-info {
				position: absolute;
				top: 10rpx;
				left: 0;
				right: 0;
				
				border-radius: 0 0 10rpx 10rpx;
				padding: 10rpx;
				
				.tag {
					color: #333;
					font-size: 24rpx;
				}
				
				.title {
					color: #333;
					font-weight: bold;
					font-size: 28rpx;
					line-height: 46rpx;
				}
			}
		}
		
		.more-card {
			display: flex;
			align-items: center;
			justify-content: center;
			color: #333;
			font-size: 28rpx;
			width: calc(100% - 20rpx);
			padding: 10rpx;
			border-radius: 10rpx;
			background: rgba(255, 255, 255, 1);
			position: absolute;
			bottom:-10rpx;
			left: 0;
			right: 0;
		}
	}
}

.product-section {
	padding:10rpx;
	// background: #fff;
	margin-top: 20rpx;
	
	.section-title {
		font-size: 32rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}
	
	.section-desc {
		font-size: 24rpx;
		color: #666;
		margin-bottom: 20rpx;
	}
	
	.product-list {
		display: flex;
		flex-wrap: wrap;
		margin: 0 -10rpx;
		justify-content: space-between;
		flex-direction: row;
		
		.product-item {
			width: 32%;
			padding: 20rpx 10rpx;
			box-sizing: border-box;
			border-radius: 20rpx;
			background: #fff;
			text-align: center;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			
			.product-info {
				padding: 10rpx 0;
				
				.product-name {
					font-size: 28rpx;
					color: #333;
					margin-bottom: 6rpx;
				}
				
				.product-price {
					font-size: 32rpx;
					color: #ff6b81;
					font-weight: bold;
					
					&::before {
						content: '¥';
						font-size: 24rpx;
						margin-right: 4rpx;
					}
				}
			}
		}
	}
}
</style>
